<?php
/**
 * Created by PhpStorm.
 * User: 徐州
 * Date: 2017/5/4
 * Time: 13:38
 */

namespace App\Models\VoteCandidate;

class VoteCandidateService
{
    private $voteCandidateRepository;

    public function __construct(\App\Contracts\Repositories\VoteCandidate\VoteCandidateRepository $voteCandidateRepository)
    {
        $this->voteCandidateRepository = $voteCandidateRepository;
    }

    /**
     * 获取所有投票选项
     * @return array
     */
    public function getAll()
    {
        return $this->voteCandidateRepository->getAll();
    }

    /**
     * 按id获取投票项
     * @param $id
     * @return array
     */
    public function getItemById($id)
    {
        return $this->voteCandidateRepository->findById($id);
    }

    public function updateResourceUrl($resourceID, $resourceUrl)
    {
        return $this->voteCandidateRepository->updateResourceUrl($resourceID, $resourceUrl);
    }

    public function getTotalNumberOfVotes($conditions)
    {
        return $this->voteCandidateRepository->getTotalNumberOfVotes($conditions);
    }

    public function getTopItemsByConditions($conditions)
    {
        return $this->voteCandidateRepository->getTopItemsByConditions($conditions)->toArray();
    }

    public function getItemsByGroup($groupId, $activityId, $limit)
    {
        return $this->voteCandidateRepository->getItemsByGroup($groupId, $activityId, $limit);
    }

    public function getByResourceId($resourceID)
    {
        return $this->voteCandidateRepository->where(['resource_id' => $resourceID]);
    }

    public function getByResourceUrl($resourceID)
    {
        return $this->voteCandidateRepository->where(['resource_url' => $resourceID]);
    }

    public function getGroupIdByActivityId($activityId, $limit)
    {
        return $this->voteCandidateRepository->getGroupIdByActivityId($activityId, $limit);
    }

    public function getIdByActivityId($activityId){
        return $this->voteCandidateRepository->getIdByActivityId($activityId);
    }
    public function getItemsByConditions($conditions, $limit_num=0)
    {
        return $this->voteCandidateRepository->getItemsByConditions($conditions, $limit_num)->toArray();
    }

    public function createCandidate($data)
    {
        return $this->voteCandidateRepository->create($data);
    }
    public function modifyCandidate($params, $where){
        return $this->voteCandidateRepository->update($params,$where);
    }

    public function getMaxOrderId($groupId, $activityId){
        return $this->voteCandidateRepository->getMaxOrderId($groupId,$activityId);
    }

    public function getMaxCode($activityId){
        return $this->voteCandidateRepository->getMaxCode($activityId);
    }
}
